/*
 * @Description: 错题报告接口封装
 * @Autor: GuluGuluu
 * @Date: 2022-12-02 17:35:33
 * @LastEditors: GuluGuluu
 * @LastEditTime: 2023-07-04 00:06:43
 */
import axios from "axios";
import Request from "../request";

const prefix = "/analyze";

const ReportService = {
  getReportList: ({ stuId }) =>
    Request.get(`${prefix}/getwrongreport?stuId=${stuId}`).then(
      (res) => res.data
    ),
  getReportListByClassId: ({ classId }) =>
    Request.get(`${prefix}/getclassreports?classid=${classId}`).then(
      (res) => res.data
    ),
  getAllExam: (id) =>
    Request.get(
      `http://localhost:8080/exam/student/list/${id}?page=1&perPage=10000`
    ).then((res) => res.data.examList),
  outputReport: ({ stuid, paperid }) =>
    Request.get(
      `${prefix}/generatewrongreport?stuid=${stuid}&examid=${paperid}`
    ).then((res) => {
      if (res.data) return res.data;
      throw res.msg;
    }),
  getAllReportsById: ({ stuId }) =>
    Request.get(`${prefix}/getallreports?stuid=${stuId}`).then(
      (res) => res.data
    ),
  deletereport: (stuid, examId) =>
    Request.delete(
      `${prefix}/deletereport?stuid=${stuid}&examid=${examId}`
    ).then((res) => res.data),
  uploadImage: ({ file, stuid, examid }) => {
    const formData = new FormData();
    formData.append("file", file);
    formData.append("stuid", stuid);
    formData.append("examid", examid);
    return axios
      .post(`http://localhost:8080${prefix}/upload`, formData, {
        headers: {
          "Content-Type": "application/form-data",
        },
      })
      .then((res) => res.data);
  },
};
export default ReportService;
